# Maintainer: MVZ Labor Ludwigsburg <edv@mvz-labor-lb.de>
# vim: ft=bash

# Inspired by https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-gcab/PKGBUILD

_realname=msitools
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.106
pkgrel=1
pkgdesc="A set of programs to inspect and build Windows Installer (.MSI) files (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://wiki.gnome.org/msitools'
msys2_repository_url="https://gitlab.gnome.org/GNOME/msitools"
license=('spdx:LGPL-2.1-or-later')
depends=("${MINGW_PACKAGE_PREFIX}-gcab"
         "${MINGW_PACKAGE_PREFIX}-libgsf")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-vala")
source=("https://download.gnome.org/sources/${_realname}/${pkgver}/${_realname}-${pkgver}.tar.xz"
        "001-wixl-heat-rename-header.patch"
        "002-use-paths-relative-to-the-installation-prefix.patch")
sha256sums=('1ed34279cf8080f14f1b8f10e649474125492a089912e7ca70e59dfa2e5a659b'
            'b3c0bc13bd0bdd6db7d6649b2000613616499d3768c6ae0d76e400890db3d0c5'
            'edba2e321f9318b1b2ffb90d0bc518eaede6a7b4fd69a1ee250d3fbc0b270dbe')

prepare() {
  cd $srcdir/${_realname}-${pkgver}

  for p in "${srcdir}"/*.patch; do
    patch -Np1 -i ${p}
  done
}

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  # clang error from vala generated file
  export CFLAGS="${CFLAGS} -Wno-incompatible-function-pointer-types"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson \
    --prefix="${MINGW_PREFIX}" \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/meson compile
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/meson install

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/copyright" \
    "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/copyright"
}
